/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cageballserver.match;

import cageballcommon.exceptions.CageballMatchException;
import java.util.Collection;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author kanonas
 */
public class MatchExecutor implements Runnable {

    private LinkedBlockingQueue<Match> queue;
    private Match match;

    public MatchExecutor() {
        queue = new LinkedBlockingQueue<Match>();
    }

    public void addMatch(Match match) {
        System.out.println("New match added!");
        queue.add(match);
    }

    public void run() {
        
        while (true) {
            try {
                match = queue.take();
                match.playMatch();
                System.out.println("Match done!");
            } catch (CageballMatchException ex) {
                Logger.getLogger(MatchExecutor.class.getName()).log(Level.SEVERE, null, ex);
            } catch (InterruptedException ex) {
                Logger.getLogger(MatchExecutor.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    public void stopMatch() {
     // TODO: Stop the current match
    }

    public Collection<Match> getMatchQueue() {
        return queue;
    }
}
